<?php

if (!defined('BASEPATH'))
	exit('No direct script access allowed');
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of model_catalogue
 *
 * @author b4by
 */
class model_catalogue extends MY_Model{
	var $table = 'catalogue';
	
	public function get_list($lang,$input = array()){
		if(!isset($input['select']))
		{
			$input['select'] = 'c.id,p_id,index,image,css,name,description,meta_desc,meta_keyword';
		}
		
		$input['where']['lang_id'] = $lang;
		
		$this->get_list_set_input($input);
		
		$this->db->from('catalogue c');
		
		$this->db->join('catalogue_info i','c.id = i.cat_id','left');
		
		$query = $this->db->get();
		
		return $query->result();
	}
	
	public function get_list_hash($lang, $input = array()) {
		$result = $this->get_list($lang, $input);
        $hash = array();
        foreach($result as $obj)
            $hash[$obj->{$this->primary_key}] = $obj;
            
        return $hash;
	}
	
	public function get_info($id, $field = '')
	{
		$data = parent::get_info($id,$field);
		if($data===FALSE) return FALSE;
		$this->load->model('model_catalogue_info');
		
		$info = $this->model_catalogue_info->get_list(array(
			'where'	=> array('cat_id'	=> $data->id),
			'order'	=> array('lang_id','asc')
		));
		foreach($info as $row)
			$data->info[$row->lang_id] = $row;
		
		return $data;
	}
}

?>
